package com.youbug.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youbug.system.entity.Carousel;
import com.youbug.system.mapper.CrouselMapper;
import com.youbug.system.service.ICarouselService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youbug.system.vo.CarouselVo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 官网轮播图存储表 服务实现类
 * </p>
 *
 * @author youbug
 * @since 2023-04-13
 */
@Service
public class CarouselServiceImpl extends ServiceImpl<CrouselMapper, Carousel> implements ICarouselService {

    @Override
    public IPage<Carousel> getCarouselPage(CarouselVo vo) {

        Page<Carousel> oageParam = new Page<>();

        oageParam.setCurrent(vo.getCurrentPage());

        oageParam.setSize(vo.getPageSize());

        QueryWrapper<Carousel> wrapper = new QueryWrapper<>();

        if(vo.getValid() != null){

            wrapper.eq("valid", vo.getValid());
        }

        Page<Carousel> page = this.page(oageParam, wrapper);

        return page;
    }

    @Override
    public List<Carousel> listBy(Carousel carousel) {

        QueryWrapper<Carousel> wrapper = new QueryWrapper<>();

        if(carousel.getValid() != null){
            wrapper.eq("valid", carousel.getValid());
        }
        this.list(wrapper);

        return this.list(wrapper);
    }
}
